package com.example.musicproject.config;

import com.example.musicproject.filter.JWTInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Autowired
    private JWTInterceptor jwtInterceptor;
    /*
    * 解决跨域问题
    * */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//允许的访问路径
                .allowedOrigins("http://192.168.201.1:8080")//允许跨域的地址
                .allowCredentials(true)//带上cookies地址
                .allowedHeaders("*")
                .exposedHeaders("*");
    }

    /*
    * 在MVC中添加拦截器
    * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/a1/**") //其他接口保护的路径
                .addPathPatterns("/common/download/**")
                .addPathPatterns("/common/qiniu/delect/**")
                .addPathPatterns("/article/**")
                .addPathPatterns("/musicInfo/**")
                .addPathPatterns("/tuku/**")
                .excludePathPatterns("/employee/qiniu/upload")
                .excludePathPatterns("/employee/**");//接口放行路径
    }


}
